package cn.cool.springframework.beans.factory.config;

import cn.cool.springframework.beans.PropertyValues;
import cn.cool.springframework.beans.factory.ListableBeanFactory;
import lombok.Data;

@Data
public class BeanDefinition {
    private final String SCOPE_SINGLETON = ConfigurableBeanFactory.SCOPE_SINGLETON;

    private final String SCOPE_PROTOTYPE = ConfigurableBeanFactory.SCOPE_SINGLETON;

    // 存储bean的全类名，这样就可以将实例化和管理bean的操作交给ioc容器控制
    private Class beanClass;

    private PropertyValues propertyValues;

    // XmlBeanDefinitionReader 加载 初始化方法
    private String initMethod;

    // XmlBeanDefinitionReader 加载 销毁方法
    private String destroyMethod;

    private String scope = SCOPE_SINGLETON;

    private boolean singleton = true;

    private boolean prototype = false;

    public BeanDefinition(Class beanClass) {
        this.beanClass = beanClass;
        this.propertyValues = new PropertyValues();
    }

    public BeanDefinition(Class beanClass, PropertyValues propertyValues) {
        this.beanClass = beanClass;
        this.propertyValues = propertyValues;
    }

    // 在xml注册 Bean定义时，通过scope字段来判断是单列还是原型
    public void setScope(String scope) {
        this.scope = scope;
        this.singleton = SCOPE_SINGLETON.equals(scope);
        this.prototype = SCOPE_PROTOTYPE.equals(scope);
    }
}